<?php

namespace App\Kuafu\Order\Model;

use App\Kuafu\Base\Model\BaseModel;
use App\Kuafu\Base\Model\Traits\KfSoftDeletes;
use App\Kuafu\Base\Model\Traits\KfUid;
use App\Kuafu\Order\Service\OrderDb;
use App\Kuafu\Order\Service\OrderTable;

class OrderExternalSplitModel extends BaseModel
{
    use KfUid;

//    protected $connection = 'mysqlOrder';

    public $timestamps = false;

    public static string $tableName;
    public static string $connectionName;

    public static function suffix($shopId)
    {
        if (is_int($shopId) && $shopId < 0) {
            $shopId = 0;
        }

        self::$tableName      = OrderTable::orderExternalTableName($shopId);
        self::$connectionName = OrderDb::orderDbConnection($shopId);

        return new static;
    }

    public function getConnectionName()
    {
        return self::$connectionName ?? parent::getConnectionName();
    }

    public function getTable()
    {
        return self::$tableName ?? parent::getTable();
    }

    public static function insertOrderExternal($data)
    {
        self::query()->insert($data);
    }

}
